package com.hb.core.pojo.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

/**
 * 发票类型
 *
 * @author jinhaolin
 * @date 2022/4/2 0002 15:05
 **/
@Getter
public enum InvoiceTypeEnum {
    DEDICATED_INVOICE(1, "004", "增值税专用发票","1.03"),
    ORDINARY_INVOICE(2, "007", "增值税普通发票","1.00"),
    ORDINARY_ELECTRONIC_INVOICE(3, "026", "增值税电子普通发票","1.00"),
    DEDICATED_ELECTRONIC_INVOICE(4, "028", "增值税电子专用发票","1.03"),
    ORDINARY_ROLL_INVOICE(5, "025", "增值税普通发票（卷式）","1.00");

    private final int code;
    private final String dicLabel;
    private final String showName;

    private final String taxRate;

    InvoiceTypeEnum(int code, String dicLabel, String showName, String taxRate) {
        this.code = code;
        this.dicLabel = dicLabel;
        this.showName = showName;
        this.taxRate = taxRate;
    }


    /**
     * @param dicLabel:发票类型
     * @Description:通过发票类型获得税率
     * @Author: zhongdl
     * @Date:2022/4/15 13:34
     * @return: {@link String }
     **/
    public static String getInvoiceTaxRate(String dicLabel) {
        if (StrUtil.isEmpty(dicLabel)) {
            return null;
        }
        InvoiceTypeEnum invoiceTypeEnum = getInvoiceTypeEnum(dicLabel);
        return invoiceTypeEnum == null ? null : invoiceTypeEnum.getTaxRate();
    }
    public static InvoiceTypeEnum getInvoiceTypeEnum(String dicLabel) {
        if (StrUtil.isEmpty(dicLabel)) {
            return null;
        }
        for (InvoiceTypeEnum invoiceTypeEnum : InvoiceTypeEnum.values()) {
            if (dicLabel.equals(invoiceTypeEnum.getDicLabel())) {
                return invoiceTypeEnum;
            }
        }
        return null;
    }
    public static String getNameByLabel(String dicLabel) {
        if (StrUtil.isEmpty(dicLabel)) {
            return null;
        }
        for (InvoiceTypeEnum invoiceTypeEnum : InvoiceTypeEnum.values()) {
            if (dicLabel.equals(invoiceTypeEnum.getDicLabel())) {
                return invoiceTypeEnum.getShowName();
            }
        }
        return null;
    }

}
